package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupfifteen.entity.SysTeacherEntity;
import com.groupfifteen.service.SysTeacherService;

import com.groupfifteen.vo.SysTeacherVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("systeacher")
public class SysTeacherController {
    @Autowired
    private SysTeacherService sysTeacherService;

    @PostMapping("/query")
    public IPage Query(@RequestBody SysTeacherVo sysTeacherVo) {

        SysTeacherEntity sysTeacherEntity = new SysTeacherEntity();
        sysTeacherEntity.setTeacherId(sysTeacherVo.getTeacherId());
        sysTeacherEntity.setTeacherName(sysTeacherVo.getTeacherName());
        sysTeacherEntity.setPwd(sysTeacherVo.getPwd());
;
        IPage<SysTeacherEntity> page = sysTeacherService.Query(sysTeacherEntity,1,10);
        return page;
    }
    //ASDFGH
    @PostMapping("addsysteacher")
    public String AddSysTeacher(@RequestBody SysTeacherEntity sysTeacherEntity) {
        Integer result = sysTeacherService.AddSysTeacher(sysTeacherEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //
    @DeleteMapping("/deletesysteacher/{teacherId}")
    public String DeleteSysTeacher(@PathVariable("teacherId") Integer teacherId) {
        Integer result = sysTeacherService.DeleteSysTeacher(teacherId);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getsysteacher/{teacherId}")
    public SysTeacherEntity GetSysTeacher(@PathVariable("teacherId") Integer teacherId) {
        SysTeacherEntity result = sysTeacherService.GetSysTeacher(teacherId);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updatesysteacher/{id}")
    public String UpdateSysuser(@PathVariable("id") int id,@RequestBody SysTeacherEntity sysTeacherEntity) {
        sysTeacherEntity.setTeacherId(id);
        Integer result = sysTeacherService.UpdateSysTeacher(sysTeacherEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //asdfgfsdfdsffdsf
    @PostMapping("getinfo")
    public String Getinfo() {
        return "success";
    }

}
